﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DAO;

namespace Sklad.WindowsApplication
{
    public partial class EditProduct : Form
    {
        private int id_product;
        private DaoRepository dao;
        private Product product;
        public EditProduct(int id)
        {
            this.id_product = id;
            dao = new DaoRepository();
            this.product = dao.ProductRepository.GetById(id_product);
            InitializeComponent();
            this.Text = product.Name;
            txt_name.Text = product.Name;
            txt_type.Text = product.Category.Name;
            txt_description.Text = product.Description;
            if (!product.Count.HasValue)
                txt_count.Text = "0";
            else
                txt_count.Text = product.Count.ToString();
        }

        private void btn_save_Click(object sender, EventArgs e)
        {
            this.product.Name = txt_name.Text;
            this.product.Description = txt_description.Text;
            dao.ProductRepository.Edit(this.product);
           
            //MainEmployeeForm mef = new MainEmployeeForm();
            //mef.BindDataGrid();
            MainEmployeeForm.bg();
            this.Dispose();
        }

        private void lbl_delete_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            dao.ProductRepository.Delete(this.id_product);
            MainEmployeeForm.bg();
            this.Dispose();
        }

        private void btn_cancel_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }
    }
}
